﻿
using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using XQ.SP.Model;

namespace XQ.SP.BllServices
{
    //用户
    public partial class UsersBLL : BaseBll
    {

        private readonly XQ.SP.DalServices.UsersDal dal = new XQ.SP.DalServices.UsersDal();
        public UsersBLL()
        { }

        #region 
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool ExistsWhere(string whereSql)
        {
            return dal.ExistsWhere(whereSql);
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(long Id)
        {
            return dal.Exists(Id);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public long Add(XQ.SP.Model.UsersItem model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 批量增加数据
        /// </summary>
        public bool AddList(List<XQ.SP.Model.UsersItem> models)
        {
            int rows = dal.AddList(models);
            if (rows > 0)
                return true;
            else
                return false;
        }


        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(XQ.SP.Model.UsersItem model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 批量更新数据
        /// </summary>
        public int UpdateList(List<XQ.SP.Model.UsersItem> models)
        {
            return dal.UpdateList(models);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(long Id)
        {

            return dal.Delete(Id);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string Idlist)
        {
            return dal.DeleteList(Idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public XQ.SP.Model.UsersItem GetModel(long Id)
        {

            return dal.GetModel(Id);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public XQ.SP.Model.UsersItem GetModelWhereStr(string whereSql)
        {

            return dal.GetModelWhereStr(whereSql);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere = "")
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<XQ.SP.Model.UsersItem> GetModelList(string strWhere = "")
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 获得新增的数据
        /// </summary>
        public List<XQ.SP.Model.UsersItem> GetModelListNew(string datetimeStr)
        {
            DataSet ds = dal.GetList(" Created>='" + datetimeStr + "' ");
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<XQ.SP.Model.UsersItem> DataTableToList(DataTable dt)
        {
            List<XQ.SP.Model.UsersItem> modelList = new List<XQ.SP.Model.UsersItem>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                XQ.SP.Model.UsersItem model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new XQ.SP.Model.UsersItem();
                    
                if (dt.Rows[n]["Id"].ToString() != "")
                {
                    model.Id = Int64.Parse(dt.Rows[n]["Id"].ToString());
                }
                if (dt.Rows[n]["UserName"].ToString() != "")
                {
                    model.UserName = dt.Rows[n]["UserName"].ToString();
                }
                if (dt.Rows[n]["NO"].ToString() != "")
                {
                    model.NO = dt.Rows[n]["NO"].ToString();
                }
                if (dt.Rows[n]["Email"].ToString() != "")
                {
                    model.Email = dt.Rows[n]["Email"].ToString();
                }
                if (dt.Rows[n]["IDCard"].ToString() != "")
                {
                    model.IDCard = dt.Rows[n]["IDCard"].ToString();
                }
                if (dt.Rows[n]["Mobil"].ToString() != "")
                {
                    model.Mobil = dt.Rows[n]["Mobil"].ToString();
                }
                if (dt.Rows[n]["RealName"].ToString() != "")
                {
                    model.RealName = dt.Rows[n]["RealName"].ToString();
                }
                if (dt.Rows[n]["UserPassword"].ToString() != "")
                {
                    model.UserPassword = dt.Rows[n]["UserPassword"].ToString();
                }
                if (dt.Rows[n]["Telephone"].ToString() != "")
                {
                    model.Telephone = dt.Rows[n]["Telephone"].ToString();
                }
                if (dt.Rows[n]["QQ"].ToString() != "")
                {
                    model.QQ = dt.Rows[n]["QQ"].ToString();
                }
                if (dt.Rows[n]["Sex"].ToString() != "")
                {
                    model.Sex = dt.Rows[n]["Sex"].ToString();
                }
                if (dt.Rows[n]["Birthday"].ToString() != "")
                {
                    model.Birthday = System.DateTime.Parse(dt.Rows[n]["Birthday"].ToString());
                }
                if (dt.Rows[n]["Address"].ToString() != "")
                {
                    model.Address = dt.Rows[n]["Address"].ToString();
                }
                if (dt.Rows[n]["Description"].ToString() != "")
                {
                    model.Description = dt.Rows[n]["Description"].ToString();
                }
                if (dt.Rows[n]["PhotoPath"].ToString() != "")
                {
                    model.PhotoPath = dt.Rows[n]["PhotoPath"].ToString();
                }
                if (dt.Rows[n]["CreateTime"].ToString() != "")
                {
                    model.CreateTime = System.DateTime.Parse(dt.Rows[n]["CreateTime"].ToString());
                }
                if (dt.Rows[n]["UpLoginTime"].ToString() != "")
                {
                    model.UpLoginTime = System.DateTime.Parse(dt.Rows[n]["UpLoginTime"].ToString());
                }
                if (dt.Rows[n]["Integral"].ToString() != "")
                {
                    model.Integral = Int32.Parse(dt.Rows[n]["Integral"].ToString());
                }
                if (dt.Rows[n]["Degree"].ToString() != "")
                {
                    model.Degree = dt.Rows[n]["Degree"].ToString();
                }
                if (dt.Rows[n]["Attest"].ToString() != "")
                {
                    model.Attest = Int32.Parse(dt.Rows[n]["Attest"].ToString());
                }
                if (dt.Rows[n]["PostsCount"].ToString() != "")
                {
                    model.PostsCount = Int32.Parse(dt.Rows[n]["PostsCount"].ToString());
                }
                if (dt.Rows[n]["PostsSaidCount"].ToString() != "")
                {
                    model.PostsSaidCount = Int32.Parse(dt.Rows[n]["PostsSaidCount"].ToString());
                }
                if (dt.Rows[n]["GoodSaidCount"].ToString() != "")
                {
                    model.GoodSaidCount = Int32.Parse(dt.Rows[n]["GoodSaidCount"].ToString());
                }
                if (dt.Rows[n]["WeiXin"].ToString() != "")
                {
                    model.WeiXin = dt.Rows[n]["WeiXin"].ToString();
                }
                if (dt.Rows[n]["UsefulCount"].ToString() != "")
                {
                    model.UsefulCount = Int32.Parse(dt.Rows[n]["UsefulCount"].ToString());
                }
                if (dt.Rows[n]["UMoney"].ToString() != "")
                {
                    model.UMoney = Int32.Parse(dt.Rows[n]["UMoney"].ToString());
                }
                if (dt.Rows[n]["UserType"].ToString() != "")
                {
                    model.UserType = Int32.Parse(dt.Rows[n]["UserType"].ToString());
                }
                if (dt.Rows[n]["Status"].ToString() != "")
                {
                    model.Status = Int32.Parse(dt.Rows[n]["Status"].ToString());
                }
                if (dt.Rows[n]["Creator"].ToString() != "")
                {
                    model.Creator = Int64.Parse(dt.Rows[n]["Creator"].ToString());
                }
                if (dt.Rows[n]["Created"].ToString() != "")
                {
                    model.Created = System.DateTime.Parse(dt.Rows[n]["Created"].ToString());
                }
                if (dt.Rows[n]["Modifier"].ToString() != "")
                {
                    model.Modifier = Int64.Parse(dt.Rows[n]["Modifier"].ToString());
                }
                if (dt.Rows[n]["Modified"].ToString() != "")
                {
                    model.Modified = System.DateTime.Parse(dt.Rows[n]["Modified"].ToString());
                }
                if (dt.Rows[n]["StuNo"].ToString() != "")
                {
                    model.StuNo = dt.Rows[n]["StuNo"].ToString();
                }
                if (dt.Rows[n]["SelfID"].ToString() != "")
                {
                    model.SelfID = dt.Rows[n]["SelfID"].ToString();
                }
                if (dt.Rows[n]["ClassName"].ToString() != "")
                {
                    model.ClassName = dt.Rows[n]["ClassName"].ToString();
                }
                if (dt.Rows[n]["RolesId"].ToString() != "")
                {
                    model.RolesId = Int64.Parse(dt.Rows[n]["RolesId"].ToString());
                }
                if (dt.Rows[n]["Roles"].ToString() != "")
                {
                    model.Roles = dt.Rows[n]["Roles"].ToString();
                }
                if (dt.Rows[n]["DepaId"].ToString() != "")
                {
                    model.DepaId = Int64.Parse(dt.Rows[n]["DepaId"].ToString());
                }
                if (dt.Rows[n]["DepaName"].ToString() != "")
                {
                    model.DepaName = dt.Rows[n]["DepaName"].ToString();
                }
                if (dt.Rows[n]["ImagesBlog"].ToString() != "")
                {
                    model.ImagesBlog = dt.Rows[n]["ImagesBlog"].ToString();
                }
                if (dt.Rows[n]["GoodCount"].ToString() != "")
                {
                    model.GoodCount = Int32.Parse(dt.Rows[n]["GoodCount"].ToString());
                }
                if (dt.Rows[n]["ParentId"].ToString() != "")
                {
                    model.ParentId = Int64.Parse(dt.Rows[n]["ParentId"].ToString());
                }
                if (dt.Rows[n]["SysDegreeId"].ToString() != "")
                {
                    model.SysDegreeId = Int64.Parse(dt.Rows[n]["SysDegreeId"].ToString());
                }
                if (dt.Rows[n]["SysDegreeName"].ToString() != "")
                {
                    model.SysDegreeName = dt.Rows[n]["SysDegreeName"].ToString();
                }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }



        /// <summary>
        /// Model的属性对应赋值
        /// </summary>
        public void ModelCopy(XQ.SP.Model.UsersItem modelOld, XQ.SP.Model.UsersItem modelNew)
        {
            
            modelNew.Id = modelOld.Id;
            modelNew.UserName = modelOld.UserName;
            modelNew.NO = modelOld.NO;
            modelNew.Email = modelOld.Email;
            modelNew.IDCard = modelOld.IDCard;
            modelNew.Mobil = modelOld.Mobil;
            modelNew.RealName = modelOld.RealName;
            modelNew.UserPassword = modelOld.UserPassword;
            modelNew.Telephone = modelOld.Telephone;
            modelNew.QQ = modelOld.QQ;
            modelNew.Sex = modelOld.Sex;
            modelNew.Birthday = modelOld.Birthday;
            modelNew.Address = modelOld.Address;
            modelNew.Description = modelOld.Description;
            modelNew.PhotoPath = modelOld.PhotoPath;
            modelNew.CreateTime = modelOld.CreateTime;
            modelNew.UpLoginTime = modelOld.UpLoginTime;
            modelNew.Integral = modelOld.Integral;
            modelNew.Degree = modelOld.Degree;
            modelNew.Attest = modelOld.Attest;
            modelNew.PostsCount = modelOld.PostsCount;
            modelNew.PostsSaidCount = modelOld.PostsSaidCount;
            modelNew.GoodSaidCount = modelOld.GoodSaidCount;
            modelNew.WeiXin = modelOld.WeiXin;
            modelNew.UsefulCount = modelOld.UsefulCount;
            modelNew.UMoney = modelOld.UMoney;
            modelNew.UserType = modelOld.UserType;
            modelNew.Status = modelOld.Status;
            modelNew.Creator = modelOld.Creator;
            modelNew.Created = modelOld.Created;
            modelNew.Modifier = modelOld.Modifier;
            modelNew.Modified = modelOld.Modified;
            modelNew.StuNo = modelOld.StuNo;
            modelNew.SelfID = modelOld.SelfID;
            modelNew.ClassName = modelOld.ClassName;
            modelNew.RolesId = modelOld.RolesId;
            modelNew.Roles = modelOld.Roles;
            modelNew.DepaId = modelOld.DepaId;
            modelNew.DepaName = modelOld.DepaName;
            modelNew.ImagesBlog = modelOld.ImagesBlog;
            modelNew.GoodCount = modelOld.GoodCount;
            modelNew.ParentId = modelOld.ParentId;
            modelNew.SysDegreeId = modelOld.SysDegreeId;
            modelNew.SysDegreeName = modelOld.SysDegreeName;
        }
        #endregion

    }
}

